package com.tsd.system.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.dao.SysUserBind3rdMapper;
import com.tsd.system.entity.SysUser;
import com.tsd.system.entity.SysUserBind3rd;
import com.tsd.system.entity.SysUserBind3rdExt;
import com.tsd.system.service.SysUserBind3rdService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysUserBind3rd 服务实现层
 *
 * @author huawei
 * @date 2021/07/18 10:53:52
 */
@Service
public class SysUserBind3rdServiceImpl extends BaseServiceImpl implements SysUserBind3rdService {

    @Resource
    private SysUserBind3rdMapper sysUserBind3rdMapper;

    @Override
    public SysUserBind3rd getSysUserBind3rdById(Long id) throws Exception {
        return sysUserBind3rdMapper.selectByPrimaryKey(id);
    }

    @Override
    public SysUserBind3rdExt queryBySid(String sid) throws Exception {
        return sysUserBind3rdMapper.selectBySid(sid);
    }

    @Override
    public void deleteSysUserBind3rd(Long id, SysUser opUser) throws Exception {
        SysUserBind3rd old = sysUserBind3rdMapper.selectByPrimaryKey(id);
        super.checkEmpty(old, "该记录不存在");
        super.autoInjectBaseData(old, opUser, TYPE_DELETE);
        sysUserBind3rdMapper.updateByPrimaryKeySelective(old);
    }

    @Override
    public void saveSysUserBind3rd(SysUserBind3rdExt record, SysUser opUser) throws Exception {
        SysUserBind3rdExt old = sysUserBind3rdMapper.selectSameObj(record);
        if (old != null) {
            record.setId(old.getId());
        }
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, TYPE_CREATE);
            sysUserBind3rdMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, TYPE_UPDATE);
            old.setDr(0);
            sysUserBind3rdMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<SysUserBind3rdExt> findSysUserBind3rds(Map<String, Object> params, PageBean page) throws Exception {
        return sysUserBind3rdMapper.selectByPage(params, page);
    }

    @Override
    public List<SysUserBind3rdExt> findSysUserBind3rds(Map<String, Object> params) throws Exception {
        return sysUserBind3rdMapper.selectByParams(params);
    }
}